package com.neu.dao;

import com.neu.util.DBUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.MapListHandler;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;
public class DeptDao {
    public int save(String no,String name,String loc){
        int row=0;
        String sql="insert into dept(deptno,dname,loc)"+
                " values(?,?,?)";
        QueryRunner qr=new QueryRunner(DBUtil.getDateSource());
        try {
            row=qr.update(sql,no,name,loc);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return row;
    }
    public List<Map<String,Object>>findBySal(double sal){
        List<Map<String,Object>> list=null;
        String sql="select * from v_emp_dept_grade"+
                " where sal>?";
        QueryRunner qr=new QueryRunner(DBUtil.getDateSource());
        try {
            list=qr.query(sql,new MapListHandler(),sal);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
    public static void main(String[] args) {
        DeptDao deptDao=new DeptDao();

        List<Map<String,Object>>list= deptDao.findBySal(2000.0);
        System.out.println(list);
    }
}






